

package cn.shengchao.examstar.product.ohs.local.message;

import cn.shengchao.base.enums.ProductType;
import cn.shengchao.examstar.product.domain.entity.*;
import lombok.Data;

import java.math.BigDecimal;

@Data
public class ProductDto {
    /**
     * 商品ID
     */
    private String productId;
    private String imageUrl;
    /**
     * 商品名称
     */
    private String productName;
    /**
     * 商品描述
     */
    private String productDesc;
    /**
     * 商品价格
     */
    private BigDecimal price;
    /**
     * 优惠价格
     */
    protected BigDecimal discountPrice;
    //COURSE,PRODUCT_MEMBER,COURSE_NODES
    private String productType;

    private String pid;

    public static ProductDto of(Product product) {
        ProductDto productDto = new ProductDto();
        productDto.setProductId(product.getId().toString());
        productDto.setProductName(product.getName().getValue());
        productDto.setProductDesc(product.getDescription());
        productDto.setPrice(product.getPrice().getPrice());
        productDto.setImageUrl(product.getImageUrl());
        productDto.setDiscountPrice(product.getDiscountPrice().getPrice());
        switch (product) {
            case CourseKnowledgeNode courseKnowledgeNode -> {
                productDto.setProductType("COURSE_NODES");
                productDto.setPid(String.valueOf(courseKnowledgeNode.getCourseId()));
            }
            case Course course -> productDto.setProductType("COURSE");
            case ProductMember productMember -> productDto.setProductType("PRODUCT_MEMBER");
            case ProductThirdCap productThirdCap -> productDto.setProductType(ProductType.PRODUCT_THIRD_CAP.name());
            case ProductThirdYcbdc productThirdYcbdc -> productDto.setProductType(ProductType.PRODUCT_THIRD_YCBDC.name());
            default -> {
            }
        }
        return productDto;
    }
}
